package com.java.laixiangdong.library.main;

import com.java.laixiangdong.library.dao.Dao;
import com.java.laixiangdong.library.view.View;

import java.util.Date;

public class Main {
    public static void main(String[] args) {
        Dao dao = new Dao();
        View view = new View();
        view.welcome();
        dao.login(view.inputLogin(), view.inputPassword());
        dao.readFile();

        out:
        while (true) {
            switch (view.choose()) {
                case 1:
                    String bookName1 = view.inputBookName();
                    String bookInfo1 = view.inputBookInfo();
                    int bookPrice1 = view.inputBookPrice();
                    Date bookPublishTime1 = view.inputBookPublishTime();
                    dao.add(bookName1, bookInfo1, bookPublishTime1, bookPrice1);

                    break;
                case 2:
                    String bookName2 = view.inputBookName();
                    dao.change(bookName2);
                    break;
                case 3:
                    String bookName3 = view.inputBookName();
                    dao.del(bookName3);
                    break;
                case 4:
                    String bookName4 = view.inputBookName();
                    dao.search(bookName4);
                    break;
                case 5:
                    int i = view.inputSortFlag();
                    dao.showAll(i);
                    break;
                default:
                    System.out.println("bye bye");
                    dao.saveFile();
                    break out;
            }
        }
    }
}
